//
//  TMGFetchGoldViewController.m
//  TMGold
//
//  Created by Mac on 2017/12/11.
//  Copyright © 2017年 tangmu. All rights reserved.
//

#import "TMGFetchGoldViewController.h"
#import "TMGGoldPartnerViewController.h"
@interface TMGFetchGoldViewController ()<STActionSheetDelegate>

@end

@implementation TMGFetchGoldViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"提金";
    [self st_setRightItemWithTitle:@"联系客服" titleColor:[UIColor whiteColor]];
    [self configSubView];
    // Do any additional setup after loading the view.
}

#pragma mark --subView
- (void)configSubView{
    UIControl * control1 = [self controlWithImageName:@"f线下自提"
                                                title:@"金店自提"
                                           titleColor:TM_orangeColor
                                         subIamgeName:@"超50"
                                                  tag:10001];
    control1.left = 20;
    control1.top = 10;
    [self.tableView addSubview:control1];
    
    UIControl * control2 = [self controlWithImageName:@"快递"
                                                title:@"快递寄送"
                                           titleColor:FlatBlue
                                         subIamgeName:@"31省"
                                                  tag:10002];
    control2.left = control1.right + 10;
    control2.top = 10;
    [self.tableView addSubview:control2];
    
}
- (UIControl*)controlWithImageName:(NSString*)imageName
                    title:(NSString*)title
                    titleColor:(UIColor*)titleColor
                    subIamgeName:(NSString*)subIamgeName
                               tag:(NSInteger)tag{
    
    UIControl * control = [[UIControl alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth/2 - 25, UIScreenWidth/2 - 25)];
    control.layer.cornerRadius = 10;
    control.clipsToBounds = YES;
    control.backgroundColor = [UIColor whiteColor];
    
    
    UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 10, 55, 55)];
    imageView.image = [UIImage imageNamed:imageName];
    imageView.centerX = control.width /2;
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    [control addSubview:imageView];
    
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(0, imageView.bottom + 10, control.width, 30)
                                                     text:title
                                                textColor:titleColor
                                                     font:25
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentCenter];
    [control addSubview:titleLable];
    
    UIImageView * subIamgeView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 10 + titleLable.bottom, control.width - 10, 17)];
    subIamgeView.image = [UIImage imageNamed:subIamgeName];
    subIamgeView.centerX = control.width /2;
    subIamgeView.contentMode = UIViewContentModeScaleAspectFit;
    [control addSubview:subIamgeView];
    
    [control addTarget:self action:@selector(onSelectedControl:) forControlEvents:UIControlEventTouchUpInside];
    
    control.tag = tag;
    return control ;
}
#pragma mark --Action Method
- (void)st_rightBarAction:(id)sender{
    STActionSheet * action = [[STActionSheet alloc] initWithTitle:nil buttonTitles:@[@"在线客服",@"拨打电话"] cancelTitle:@"取消" delegate:self];
    [action show];
}
- (void)onSelectedControl:(UIControl*)control{
    if (control.tag == 10001) {
        //金店自提
        [self.navigationController pushViewController:[TMGGoldPartnerViewController new] animated:YES];
    }else{
        //快递
        [self st_rightBarAction:nil];
    }
}
#pragma mark --STActionSheetDelegate
- (void)actionSheet:(STActionSheet *)actionSheet didClickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 0) {
       [TMUtils gotoCustomServiceViewController];
    }
    if (buttonIndex == 1) {
        //拨打电话
        NSMutableString* str = [[NSMutableString alloc] initWithFormat:@"telprompt://%@",serviceCustomPhpne];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    }
}
@end
